<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();

class Login extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		
		$index	= $this->config->item('index_page');
		$host	= $this->config->item('base_url');

		$this->url = empty($index) ? $host : $host . $index . '/';
		$this->load->model('mlogin'); //load model
		

		//get session.. 'user' tuh nama session yang udah di set 
//		$this->user	= unserialize(base64_decode($this->session->userdata('user')));		
	}
	
	function index(){
		$param['url'] = $this->url;
		$view['header'] = $this->load->view('admin/header/header', $param, true);
		$view['menu'] = $this->load->view('admin/menu/menu2', $param, true);
		$view['content'] = $this->load->view('admin/rcontent/login/login', $param, true);
		$this->load->view('index', $view);
	}
	
	function act_login()
	{
		$post['username'] = $this->input->post('username',true);
		$post['password'] = $this->input->post('password',true);
		
		$query = $this->mlogin->login($post);
		// echo $query;die();
		if($query) // if the user's credentials validated...
		{
			$data = array(
				'username' => $post['username'],
				'logged_in' => true
			);
			//$this->session->set_userdata($data);
			$this->session->set_userdata('user', base64_encode(serialize($data)));
			redirect('admin/home');
//			header("Location: $this->url");

		}
		else // incorrect username or password
		{
			$this->index();
		}
		

	}
}